package cn.finedo.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class DirDataUtil {

    private static Logger logger = LoggerFactory.getLogger(DirDataUtil.class);

    /**
     * 获取文件目录
     * @author	2018056
     * @date 2021年12月25日 下午4:22:47
     * @return
     */
    public static String getMountDirectory(String uploadpath){
        String[] patharray = uploadpath.split(",");
        logger.info("路径列表：{}" ,patharray.length );
        int index = patharray.length == 1 ?0:(int)(Math.random()*10)/(patharray.length-1);
        logger.info("路径index:[{}]",index);
        return getHandMdir(patharray[index]);
    }

    //获取处理目录分隔符后的目录
    public static String getHandMdir(String uploadpath){
        String filepath = uploadpath;
        if(!isEndSeparator(uploadpath)){
            filepath += File.separator;
        }
        return filepath;
    }


    public static boolean isEndSeparator(String dirpath){
        char seperator = dirpath.charAt(dirpath.length()-1);
        if( seperator == '/'  || seperator == '\\'){
            return true;
        }
        return false;
    }
}
